﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;

using System.Web.UI;

namespace Esint.Common.Web
{
    public static partial class  ControlExtend
    {
        #region GridView Extend

        #region GridViewRow
        public static void SetDeleteMsg(this System.Web.UI.WebControls.GridViewRow row, string control)
        {
            ((System.Web.UI.WebControls.LinkButton)row.FindControl(control)).Attributes.Add("onclick", "return confirm('你确认要删除该记录吗？');");
        }

        public static void SetDeleteMsg(this System.Web.UI.WebControls.GridViewRow row, string control, string msg)
        {
            ((System.Web.UI.WebControls.LinkButton)row.FindControl(control)).Attributes.Add("onclick", "return confirm('" + msg + "');");
        }

        #endregion

        #region GridViewSortEventArgs


        public static string ToSortString(this GridViewSortEventArgs e, object sender)
        {
            GridView s = (GridView)sender;
            string sortDirection = s.Attributes["SortDirection"];
            if (e.SortExpression == s.Attributes["SortExpression"])
            {
                //获得下一次的排序状态
                sortDirection = s.Attributes["SortDirection"] == "ASC" ? "DESC" : "ASC";
            }
            s.Attributes["SortExpression"] = e.SortExpression;
            s.Attributes["SortDirection"] = sortDirection;
            return e.SortExpression + " " + sortDirection;
        }

        public static void ShowMessage(this UpdatePanel updatePanel, string msg)
        {
            System.Web.UI.ScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), "updateScript", "alert('" + msg + "');", true);
        }
        public static void ShowMessage(this UpdatePanel updatePanel, string msg, string url)
        {
            System.Web.UI.ScriptManager.RegisterStartupScript(updatePanel, updatePanel.GetType(), "updateScript", "alert('" + msg + "');window.location.href='" + url + "';", true);

        }
        #endregion

        #endregion
    }
}
